#ifndef _MAINWINDOW_H
#define _MAINWINDOW_H

#include <QMainWindow>
#include <QToolBox>
#include <QTreeWidget>
#include <QTreeView>
#include <QTableView>
#include <QListWidget>
#include "cfgparser/cfgparser.h"
#include "liteconnector/liteconnector.h"
#include "forms/newdb/newdb.h"
#include "types/movies.h"
#include "types/albums.h"

/*!
 * The MainWindow Class allows the definition of the Main Window of the
 * application.
 * @author Yannis Mazzer
 */

//typedef QList<Movie *> MovieList;

class MainWindow: public QMainWindow
{
	Q_OBJECT
		/*don't include private slots in the class definition
		 * if you haven't inserted the Q_OBJECT line */
public:
/*!
 * This is the MainWindow constructor.
 */
	MainWindow();

/*!
 * This is the MainWindow destructor.
 */
	~MainWindow();

private slots:

/*!
 * This slot popups the about dialog which describes the application.
 */
	void about();

/*!
 * This slot popups the new database form which is used to add a database.
 */
	void newdbslot();

/*!
 * This overload is provided by convenience to draw a new database form
 * from another one, this is useful when an error occured when connecting to
 * the database.
 * @param dialog an already filled new database dialog.
 */
	void newdbslot(newdbDialog *dialog);

/*!
 * This overload is provided by convenience to draw a new database form
 * from passed arguments, this is useful when creating the form from values
 * stored in the config file.
 * @param type the driver used to connect to the database.
 * @param host the Hostname of the server hosting the database.
 * @param name the name of the database or the file if SQLite.
 * @param port the port to which the database daemon is listening.
 * @param user the login used to connect.
 * @param nick a nickname the user wants to use for the added database.
 * @param comm a comment the user wants to use for the added database.
 */
	void newdbslot(const QString &type,
			const QString &host,
			const QString &name,
			const QString &port,
			const QString &user,
			const QString &nick,
			const QString &comm);

/*!
 * This slot is used when the user wants to add a new Movie to the database.
 * It updates the central widget to an empty Movie form.
 */
	void newMovieSlot();

/*!
 * This slot is used when the user wants to add a new Album to the database.
 * It updates the central widget to an empty Album form.
 */
	void newAlbumSlot();

/*!
 * This slot is used when the user wants to delete the current viewed Media.
 */
	void deleteSlot();

/*!
 * This slot checks the newly added database connection state and fill the
 * Treeview with retrieved media if the connection is established or redraw
 * the new database form.
 */
	void fillLists();

/*!
 * This slot updates the central widget so that it shows a Movie Widget
 * containing the informations of the record @ index in the Model.
 * @param index the index of the wanted record in the database.
 */
	void updateMovieView(const QModelIndex &index);

/*!
 * This slot updates the central widget so that it shows a Album Widget
 * containing the informations of the record @ index in the Model.
 * @param index the index of the wanted record in the database.
 */
	void updateAlbumView(const QModelIndex &index);

/*!
 * This slot was used when new widgets were drawn in a QTabWidget, it is not
 * used currently but will be. It closes the active tab if there is one in
 * the central QTabWidget.
 */
	void closeActiveTab();

/*!
 * This slot is not used yet, it will change the currently used database
 * to the one selected in the list.
 * @param idx index of the wanted database in the list.
 */
	void connectToDbFromList(QModelIndex idx);


private:

/*!
 * This procedure creates the actions which will be connected to the menu
 * entries.
 */
	void createActions();

/*!
 * This procedure creates the statusbar and write a welcome message in it.
 */
	void createStatusBar();

/*!
 * This procedure creates the dock widgets which are used to show the
 * databases list and the media list.
 */
	void createDocks();

/*!
 * This procedure populates the menubar.
 */
	void createMenu();

	QMenu *fileMenu;
	QMenu *editMenu;
	QMenu *viewMenu;
	QMenu *toolMenu;
	QMenu *helpMenu;

	Config *cfg;

	QDockWidget *dbDock;
	QDockWidget *contentDock;
	QListWidget *dbList;
	QToolBox *contentBox;
	QTreeView *movieView;
	QTreeView *albumsView;
	QSqlTableModel *albumModel;
	QSqlTableModel *movieModel;
	QWidget *currentMedia;
	Movie *currentMovie;
	Album *currentAlbum;
	QTabWidget *central;
	QPushButton *closeTabButton;
	QIcon closeIcon;
	AlbumList albumList;
	MovieList openedMovies;

	newdbDialog *dbDialog;
	dbConnector *currentDb;
	QList<dbConnector *> dbPointerList;
	QAction *newdbAct;
	QAction *quitAct;
	QAction *newMovieAct;
	QAction *newAlbumAct;
	QAction *deleteAct;
	QAction *aboutAct;
	QAction *aboutQtAct;


};
#endif

